package com.beilang.hotline.person.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.beilang.base.core.model.BaseModel;
import com.beilang.base.util.StringUtil;

import edu.emory.mathcs.backport.java.util.Arrays;

@Entity
@Table(name = "ht_person")
public class PersonModel extends BaseModel {

	private static final long serialVersionUID = -2592223227780172977L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "person_id")
	private Long personId;
	
	@Column(name = "company_id")
	private Long companyId;
	
	@Transient
	private String companyName;
	
	@Column(name = "name")
	private String personName;
	
	@Column(name = "sex")
	private String sex;
	
	@Transient
	private String sexDesc;	
	
	@Column(name = "telno")
	private String telNo;
	
	@Column(name = "telext")
	private String telExt;
	
	@Transient
	private String fullTel;
	
	@Column(name = "handphone")
	private String handPhone;
	
	@Column(name = "email")
	private String email;
	
	@Column(name = "access_system")
	private String accessSystem;

	@Transient
	private boolean teleBackInd;

    @Column(name = "teleBackInd")
    private String teleBackIndStr;

    @Transient
	private boolean surveyInd;

    @Column(name = "surveyInd")
    private String surveyIndStr;

    @Transient
	private List accessSystemList;


	@Column(name = "delete_ind")
    private String deleteInd="N";

    public List getAccessSystemList() {
		if(StringUtil.isNullOrBlank(accessSystem)) return new ArrayList();
	    return Arrays.asList(StringUtil.split(accessSystem,"|"));
	}

	public void setAccessSystemList(List accessSystemList) {
		this.accessSystemList = accessSystemList;
	}

	public Long getPersonId() {
		return personId;
	}

	public void setPersonId(Long personId) {
		this.personId = personId;
	}

	public Long getCompanyId() {
		return companyId;
	}

	public void setCompanyId(Long companyId) {
		this.companyId = companyId;
	}

	public String getPersonName() {
		return personName;
	}

	public void setPersonName(String personName) {
		this.personName = personName;
	}

	public String getTelNo() {
		return telNo;
	}

	public void setTelNo(String telNo) {
		this.telNo = telNo;
	}

	public String getTelExt() {
		return telExt;
	}

	public void setTelExt(String telExt) {
		this.telExt = telExt;
	}

	public String getHandPhone() {
		return handPhone;
	}

	public void setHandPhone(String handPhone) {
		this.handPhone = handPhone;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getAccessSystem() {
		return accessSystem;
	}

	public void setAccessSystem(String accessSystem) {
		this.accessSystem = accessSystem;
	}

	public String getCompanyName() {
		return companyName;
	}

	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}

	public String getFullTel() {
		if(StringUtil.isNullOrBlank(telExt)) return telNo;
		else return telNo+"-"+telExt;
	}

	public void setFullTel(String fullTel) {
		this.fullTel = fullTel;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getSexDesc() {
		return sexDesc;
	}

	public void setSexDesc(String sexDesc) {
		this.sexDesc = sexDesc;
	}

    public String getDeleteInd() {
        return deleteInd;
    }

    public void setDeleteInd(String deleteInd) {
        this.deleteInd = deleteInd;
    }

    public boolean isTeleBackInd() {
        return teleBackInd;
    }

    public void setTeleBackInd(boolean teleBackInd) {
        this.teleBackInd = teleBackInd;
        if(teleBackInd){
            this.teleBackIndStr="Y";
        }else{
            this.teleBackIndStr="N";            
        }
    }

    public boolean isSurveyInd() {
        return surveyInd;
    }

    public void setSurveyInd(boolean surveyInd) {
        this.surveyInd = surveyInd;
        if(surveyInd){
            this.surveyIndStr="Y";
        }else{
            this.surveyIndStr="N";            
        }
    }

    public String getTeleBackIndStr() {
        return teleBackIndStr;
    }

    public void setTeleBackIndStr(String teleBackIndStr) {
        this.teleBackIndStr = teleBackIndStr;
        teleBackInd = "Y".equalsIgnoreCase(teleBackIndStr);
    }

    public String getSurveyIndStr() {
        return surveyIndStr;
    }

    public void setSurveyIndStr(String surveyIndStr) {
        this.surveyIndStr = surveyIndStr;
        surveyInd = "Y".equalsIgnoreCase(surveyIndStr);
    }
}
